package com.rd.teacher.jichao.day16;

public class TestCave {

    public static void main(String[] args) {
        Cave cave = new Cave();
        for (int i = 0; i < 10; i++) {
            new Thread(cave, "person" + i).start();
        }
    }
}

class Cave implements Runnable {
    // 记录通过山洞的人数
    int crossNum = 0;

    @Override
    public void run() {
        cross();
    }

    public synchronized void cross() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        crossNum++;
        System.out.println(Thread.currentThread().getName() +
                " 通过了山洞，这是第" + crossNum + "个用户");
    }
}
